Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add size-limit bundle size analysis tool #705

Merged
merged 12 commits into from
Aug 29, 2020
Merged

Conversation

andresz1
Copy link
Contributor

@andresz1 andresz1 commented May 1, 2020

Performance budget tool

This PR is an initial idea (something that I thought that maybe could be useful after @jaredpalmer tweet) of how a performance budget tool could be added automatically in every template. Having this kind of tool helps you to keep your library bundle size as small as possible. I like size-limit because besides the size it can calculate the time it would take a browser to download and execute your JS.

I added @size-limit/preset-small-lib by default but in case that library size increases, it could be easily replaced by @size-limit/preset-big-lib (adding time).

Bundle size check

yarn size
Screenshot 2020-05-01 at 13 47 24

Bundle analyze

yarn analyze
Screenshot 2020-05-01 at 13 47 57

GitHub action

The action added (size-limit-action) will execute size-limit a comment the PRs made with the comparison of it.

pr

Any feedback would be appreciated and I'd be more than happy to iterate over a solution if you like the idea. Thanks in advance and for the great tool!

@andresz1
Copy link
Contributor Author

Hi @agilgur5! please let me know if you have any thoughts about this! 🙏

@agilgur5
Copy link
Collaborator

agilgur5 commented May 16, 2020

Hey @andresz1 I definitely like the changes, thank you for the PR! I took a look when you first made the PR, but I just haven't had the time to dive deeper and review all the pieces of this.
There are a handful of related issues and some code that was commented out from removed features related to this that I need to sort through, understand how size-limit may differ from those, think through template vs. dependency route, investigate any potential impact on multi-entry and/or preserveModules, and actually review the code

@andresz1
Copy link
Contributor Author

andresz1 commented May 19, 2020

Hi @agilgur5! I'm glad you like the idea 🎉 and thank you for the reply. Let me know if you need help. Is there any tsdx discord or spectrum channel where we could discuss ?

This was linked to issues Jul 26, 2020
@agilgur5 agilgur5 changed the title Add a performance budget tool Add a bundle size analysis tool Jul 26, 2020
@agilgur5
Copy link
Collaborator

agilgur5 commented Jul 26, 2020

Sorry for the delay on reviewing this, I've been incredibly stressed and busy, so larger PRs to add features got pretty backlogged as they take a good bit of time to really dive into.

There are a handful of related issues and some code that was commented out from removed features related to this that I need to sort through

Here's a few past references:

Summarizing, rollup-plugin-size-snapshot was previously used and still has some unused / commented out code references to it, rollup-plugin-visualizer was previously considered, and rollup-plugin-analyzer was previously recommended

understand how size-limit may differ from those

Did a quick glance through on NPM trends and size-limit seems to have a lot of nicer features:

  • currently maintained (some alternatives are not)
  • also does timing (none of the others do)
  • also does visualization (most of the others don't)
  • doesn't need to be added to Rollup build (some of the others do)

That being said, it does have more dependencies like webpack which I'm not sure are necessary for our use-case considering TSDX bundles everything with Rollup. It looks like webpack is a plugin though and can be disabled, but is included in @size-limit/preset-small-lib. The visualizations aren't as fancy as rollup-plugin-visualizer but probably nbd.

think through template vs. dependency route

Can probably stick to template initially as a testing ground and then move to a dependency later if there is enough usage. Though with #634 we're moving a bit away from dependencies.

investigate any potential impact on multi-entry and/or preserveModules

I think this will require something like webpack to bundle pieces. Multi-entry it would need to show each entry and preserveModules should theoretically all be bundled up from one entry. It looks like this can be configured with size-limit

and actually review the code

In progress.

Is there any tsdx discord or spectrum channel where we could discuss ?

No, and I don't think that would be helpful either. Keeping discussions async and transparent on a PR is ideal. Watching those channels would take more time as well.

Copy link
Collaborator

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 questions and a few changes needed to all CI workflows, but the rest looks good! Thank you for the PR and sorry for the wait.

templates/basic/.github/workflows/size.yml Outdated Show resolved Hide resolved
templates/basic/.github/workflows/size.yml Outdated Show resolved Hide resolved
templates/basic/.github/workflows/size.yml Outdated Show resolved Hide resolved
Comment on lines +9 to +10
env:
CI_JOB_NUMBER: 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the purpose of this? I found https://github.com/ai/ci-job-number, but this doesn't run a matrix in any case; there is only one job here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to remember why this was needed 😱 I tried without it and the problem is that size-limit doesn't work properly in the action (it throws an error), so for now is needed. I'll try to investigate more about this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have a log of the error? Since this is the only job in this new workflow, making it go first shouldn't be necessary, but maybe the action relies on this variable being specified in order to work

src/templates/basic.ts Show resolved Hide resolved
@agilgur5
Copy link
Collaborator

agilgur5 commented Jul 26, 2020

Ah, also

Co-authored-by: Anton Gilgur <agilgur5@gmail.com>
@vercel

This comment has been minimized.

@vercel vercel bot temporarily deployed to Preview July 30, 2020 19:51 Inactive
Co-authored-by: Anton Gilgur <agilgur5@gmail.com>
Copy link
Collaborator

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for iterating on this after the long delay @andresz1!

Changes look mostly good, a few modifications to the docs requested. There are also 3 unresolved comments above that didn't get fixed/responded to last time around. Once those are resolved this should be good to go!

templates/basic/README.md Outdated Show resolved Hide resolved
templates/basic/README.md Outdated Show resolved Hide resolved
templates/basic/README.md Outdated Show resolved Hide resolved
@agilgur5 agilgur5 added the scope: templates Related to an init template, not necessarily to core (but could influence core) label Aug 19, 2020
@agilgur5
Copy link
Collaborator

@andresz1 I'd make the changes myself and merge but there were some unresolved questions remaining from previous review that I was hoping you could answer

Co-authored-by: Anton Gilgur <agilgur5@gmail.com>
@vercel vercel bot temporarily deployed to Preview August 25, 2020 20:22 Inactive
Co-authored-by: Anton Gilgur <agilgur5@gmail.com>
@vercel vercel bot temporarily deployed to Preview August 25, 2020 20:22 Inactive
Co-authored-by: Anton Gilgur <agilgur5@gmail.com>
@andresz1
Copy link
Contributor Author

@agilgur5 sorry I was on vacations and thank you so much for the great feedback! I just answered your questions and made so changes!

@agilgur5
Copy link
Collaborator

@andresz1 no worries on the delay or if you're on vacation, everyone does that. Was just following up, especially since I couldn't find the answers to some of these myself.

Copy link
Collaborator

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work and iterations! thanks for investigating the issues -- we'll have to check back on the CI_JOB_NUMBER comment but that can be in a separate PR or done in later comments, this is ready to merge 🙂

This unfortunately didn't make v0.13.x, but will be released in v0.14.0

@agilgur5 agilgur5 changed the title Add a bundle size analysis tool Add size-limit bundle size analysis tool Aug 29, 2020
@agilgur5 agilgur5 merged commit 2938ed9 into jaredpalmer:master Aug 29, 2020
@agilgur5
Copy link
Collaborator

@all-contributors please add @andresz1 for code, doc, example

@allcontributors
Copy link
Contributor

@agilgur5

I've put up a pull request to add @andresz1! 🎉

paul-vd pushed a commit to EezyQuote/tsdx that referenced this pull request Dec 1, 2020
…mer#705)

- Add size-limit and size-limit-action to all templates
  - Use `@size-limit/preset-small-lib` by default
  - Add `yarn size` and `yarn visualize` scripts

- Remove outdated references to rollup-plugin-size-snapshot

Co-authored-by: Anton Gilgur <agilgur5@gmail.com>
Repository owner locked as resolved and limited conversation to collaborators Mar 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
scope: templates Related to an init template, not necessarily to core (but could influence core)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add bundle size GH action to all templates How to explore bundle size? Explore rollup-plugin-visualizer
2 participants